﻿using System;


namespace HAVNet.Core.Time
{
    public class UnixTime
    {
        public static uint dateTime2FechaUNIX(DateTime d)
        {
            TimeSpan value = (TimeSpan)d.Subtract(new DateTime(1970, 1, 1, 0, 0, 0));

            if (value.TotalSeconds < 0) return (uint)0;
            if (value.TotalSeconds > (double)uint.MaxValue) return (uint)uint.MaxValue;

            return (uint)value.TotalSeconds;
        }

        public static DateTime fechaUNIX2DateTime (uint d)
        {
            return new DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(d);
        }
    }
}
